<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	import urlUtil from "@/static/js/urlUtil.js"
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		computed:{
			...mapState(useLoginUserStore, ['userId'])
		},
		data() {
			return buildSubFormData({
				reviewUserCacheKey:"mkt-dd-salesOrderReview-title7-reviewUser-cache",
				orgReviewConfigCache:"mkt-dd-salesOrderReview-title7-orgReviewConfig-cache"
			})
		},
		methods:{
			initLoad(){
				let _that = this
				let pro1 = _that.om.request('tsysdict/getCombobox',{code:'38606'})
				Promise.all([pro1]).then(res=>{
					_that.$refs.autoform.changeEditor("title7",'reviewResultId','data',configSelectData(res[0],'id','dicname'))
					_that.$refs.autoform.initSelectIndex("title7",'reviewResultId')
				})
			},
			clearReview(){
				let _that = this
				_that.$refs.autoform.formdata.reviewContentId = ''
				_that.$refs.autoform.clear("title7","reviewContent")
				this.changeReview()
			},
			changeReview(){
				let _that = this
				_that.$refs.autoform.changeEditor('title7','reviewUserId',{
						link: '../../public/pageSearch/pageSearch',
						"linkParam": {
							other: JSON.stringify({
							}),
							namefield: "userName",
							searchfield: 'q',
							url: urlUtil.officePageUrl().url,
							cachename: _that.reviewUserCacheKey,
							placeholder: "请输入姓名"
					}
				});
			},
			onSelectReviewContent(item){
				let _that = this
				_that.$refs.autoform.changeEditor('title7','reviewUserId',{
						link: '../../public/pageSearch/pageSearch',
						"linkParam": {
							other: JSON.stringify({
								contentId:item.id
							}),
							namefield: "username",
							method:"post",
							searchfield: 'q',
							initload:true,
							noLoadMore:true,
							url:"salesOrderReview/findReviewUserList",
							cachename: _that.reviewUserCacheKey,
							placeholder: "请输入姓名"
					},
				});
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.reviewUserCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.reviewUserId = d.id
							formdata.reviewUserName = d.username || d.userName
							uni.removeStorage({
								key:_that.reviewUserCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.orgReviewConfigCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							if(Object.prototype.toString.call(res.data) === '[object String]'){
								formdata.reviewContent = res.data
							}else{
								formdata.reviewContent = d.dicname
								formdata.reviewContentId = d.id
							}
							_that.$refs.autoform.clear('title7','reviewUserId')
							_that.onSelectReviewContent(d)
							uni.removeStorage({
								key:_that.orgReviewConfigCache
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor('title7','reviewContent',{
									link: '../../public/pageSearch/pageSearch',
									"linkParam": {
										other: JSON.stringify({
										}),
										namefield: "dicname",
										searchfield: 'q',
										initload:true,
										url: "orgReviewConfig/getList",
										cachename: _that.orgReviewConfigCache
									}
								},null,_that.autoformdata);
								_that.initLoad()
							}
						}
					})
					_that.$nextTick(function(){
						if(_that.checkedit){
							if(_that.$refs.autoform.formdata.reviewUserId != _that.userId){
								_that.$refs.autoform.changeEditor("title7","reviewResultId",'type','')
								_that.$refs.autoform.changeEditor("title7","reviewRemark",'type','')
							}
						}
						_that.changeReview()
					})
				}
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                  
